package cn.tedu.uep.function.controller;

import cn.tedu.uep.base.response.JsonResult;
import cn.tedu.uep.function.pojo.dto.FunctionQuery;
import cn.tedu.uep.function.pojo.dto.FunctionSaveParam;
import cn.tedu.uep.function.pojo.vo.FunctionVO;
import cn.tedu.uep.function.service.FunctionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/function")
public class FunctionController {
    @Autowired
    private FunctionService functionService;

    /*查询服务种类*/
    @GetMapping("select")
    public JsonResult selectFunction(FunctionQuery functionQuery) {
        log.debug("查询服务种类参数{}",functionQuery);
        List<FunctionVO> list = functionService.selectFunction(functionQuery);
        return JsonResult.ok(list);
    }

    /*新增服务种类*/
    @PostMapping("save")
    public JsonResult saveFunction(FunctionSaveParam functionSaveParam) {
        log.debug("新增服务种类参数{}",functionSaveParam);
        functionService.saveFunction(functionSaveParam);
        return JsonResult.ok();
    }

    /*修改服务种类*/
    @PostMapping("update")
    public JsonResult updateFunction(FunctionSaveParam functionSaveParam) {
        log.debug("修改服务种类参数{}",functionSaveParam);
        functionService.saveFunction(functionSaveParam);
        return JsonResult.ok();
    }

    /*删除服务种类*/
    @PostMapping("delete/{functionId}")
    public JsonResult deleteFunction(@PathVariable Integer functionId) {
        log.debug("删除服务种类参数{}",functionId);
        functionService.deleteFunction(functionId);
        return JsonResult.ok();
    }
}
